package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.common;

import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;

import java.util.UUID;

public class FortitudeSkill extends BaseSkill {
    public static UUID uuid = UUID.fromString("3fb06284-58ab-24f3-ce92-9c24a0e20021");

    public FortitudeSkill(int level) {
        super(level);
    }

    public FortitudeSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public FortitudeSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("坚韧技能，可以提升（level*10）（基础）的生命");
    }

    @Override
    public boolean onAttribute(MobEntity mobEntity) {
        EntityAttributeModifier modifier = new EntityAttributeModifier(uuid, getName(), getSkillLevel() * 10, EntityAttributeModifier.Operation.fromId(0));
        EntityAttributeInstance entityAttributeInstance = mobEntity.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
        if (entityAttributeInstance == null) return true;
        if (!entityAttributeInstance.hasModifier(modifier))
            entityAttributeInstance.addPersistentModifier(modifier);
        return true;
    }

}
